package com.ignitetest.datanode;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;

import java.util.Arrays;

/**
 * Created by User on 2017/5/12.
 */
public class DataNodeClient2 {
    public  static void main(String[] args) {
        Ignition.setClientMode(true);


        IgniteConfiguration cfg = new IgniteConfiguration();

        TcpDiscoveryMulticastIpFinder ipFinder =new TcpDiscoveryMulticastIpFinder();
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47509"));
        TcpDiscoverySpi tcpDiscoverySpi =new TcpDiscoverySpi();
        tcpDiscoverySpi.setIpFinder(ipFinder);
        cfg.setDiscoverySpi(tcpDiscoverySpi);

        try (Ignite ignite = Ignition.start(cfg)) {
            IgniteCache<Integer, String> cache = ignite.getOrCreateCache("personCache");
            cache.query(new SqlFieldsQuery("insert into Person(id, firstName,lastName) values(1, '1','1')"));
        }
    }
}
